#include "app.h"
#include "os/types.h"
#include "os/os.h"
#include "os/nvm.h"
#include "utils/utils.h"
#include "utils/logger.h"
#include "communication/message.h"

static bool _app_log_enable = false;
static u32 app_task(void*);
static u32 log_task(void*);
static void nvm_sys_init(void);

void app_start(void) {
	message_init();
	set_log_level(MOD_SYSTEM, L_debug);
	nvm_sys_init();
}

#ifdef USE_MEX_CMD
static void nvm_sys_init(void) {
	u32 addr[] = {CONFIG_NVM0_ADDRESS, CONFIG_NVM1_ADDRESS};
	u32 pieces[] = {NVM_SYS_CONF_SIZE, NVM_APP_CONF_SIZE, NVM_MC_CONF_SIZE};
	nvm_init(addr, pieces);
}

#else
static void nvm_block_init(int nr, u32 offset, u32 size) {
	u32 addr[] = {CONFIG_NVM0_ADDRESS + offset, CONFIG_NVM1_ADDRESS + offset};
	nvm2_init(nr, addr, size);
}

static void nvm_sys_init(void) {
	nvm_block_init(NVM_SYS_CONF_PIECE, NVM_SYS_CONF_ADDR_OFFSET, NVM_SYS_CONF_SIZE);
	nvm_block_init(NVM_MC_CONF_PIECE, NVM_MC_CONF_ADDR_OFFSET, NVM_MC_CONF_SIZE);
	nvm_block_init(NVM_APP_CONF_PIECE, NVM_APP_CONF_ADDR_OFFSET, NVM_APP_CONF_SIZE);
}
#endif

